home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
422_02
/
misc
/
windemo.c
< prev
Wrap
C/C++ Source or Header
|
1994-03-20
|
12KB
|
480 lines
/*
* Program to demonstrate the MICRO-C/PC WINDOWING library.
*
* Copyright 1989-1994 Dave Dunfield
* All rights reserved.
*
* Permission granted for personal (non-commercial) use only.
*
* Compile command: cc windemo -fop
*/
#include <stdio.h> /* Standard I/O definitions */
#include <window.h> /* Window I/O definitions */
/* Color index's for different window types */
#define MENU 0
#define FORM 1
#define TEXT 2
#define PAUSE 3
/* Pointer to active color selections, and default values */
unsigned *color,
m_colors[] = { 0x70, 0x07, 0x70, 0x07 }, /* Monochrome defaults */
c_colors[] = { 0x21, 0x17, 0x67, 0x42 }; /* Color defaults */
/* Pointer for access to title window */
struct WINDOW *titlewin;
/* Introductory pre-ramble */
char *intro[] = {
"",
" This program demonstrates some of the capabilities of the MICRO-C",
"PC windowing libary. This package allows you to produce nice looking",
"DOS applications with little effort. When coupled with MICRO-C's TSR",
"function, even TSR's become simple to write... The windowing library",
"automatically saves and restores the interrupted programs video.",
"",
" If you order the MICRO-C compiler package, which includes complete",
"source code for the compiler, libraries and utilities, you will also",
"receive source code and documentation for a large selection of useful",
"MICRO-C library functions and utility programs (Over 1 Meg total). The",
"source for the windowing library is part of that collection.",
"",
"See the included CATALOG file for ordering information.",
"",
"Enjoy MICRO-C...",
"",
" Dave Dunfield",
"",
"Press any key to proceed...",
0 };
/* Main selection menu */
char *main_menu[] = {
"Library functions",
"Window creation",
"Window scrolling",
"Concurrent windows",
"Form entry",
"OPEN attributes",
"Set window colors",
"Clear main window",
0 };
/* Colors selection menu */
char *menu1[] = {
"Menu window colors",
"Form window colors",
"Text window colors",
"Pause window colors",
0 };
/* Available colors */
char *menu2[] = {
"Black",
"Blue",
"Green",
"Cyan",
"Red",
"Magenta",
"Brown",
"White",
0 };
/* Sample input form */
char *form[] = {
50<<8|6,
"\x01\x00\x20Software :",
"\x01\x01\x20Author :",
"\x01\x02\x20Directory :",
"\x01\x03\x20Filename :",
0 };
/* Data areas for input form */
char software[0x21] = "MICRO-C",
author[0x21] = "Dave Dunfield",
directory[0x21] = "C:\\MC",
filename[0x21] = "MC*.*";
/* Help text for form entry window */
char *ftext[] = {
"Use ARROW keys to move around form",
"HOME/END moves to START/END of line",
"PgUp clears entire line, PgDn clears to end",
"INSERT toggles insert ON/OFF (Observe cursor)",
"DELETE deletes the character under cursor",
"BACKSPACE deletes character preceeding cursor",
"Press ESCAPE to return to the main menu",
0 }
/* Window attribute bits & corresponding defaults */
char *atext[] = {
"SAVE/RESTORE screen under window",
"Enable SINGLE LINE border",
"Enable DOUBLE LINE border",
"CLEAR window on entry",
"CLEAR window on exit",
"NEWLINE(0x0A) = LF only",
"Enable SCROLLING",
"Enable LINE-WRAP" };
char wattrs[8] = { 1, 1, 0, 1, 0, 0, 1, 1 };
/* Help text for attribute checkout window */
char *awtext[] = {
"Use ARROW keys to move around",
"HOME = Clear entire window",
"PgUp = Clear to end of window",
"PgDn = Clear to end of line",
"ENTER = Newline character",
"ESCAPE = Return to previous menu",
0 };
/* Rambling about basic window functions (screen 1) */
char *basic1[] = { /* Screen 1 */
"",
"The basic window functions (written in assembler) are:",
"",
" wopen - Open a new window",
" wclose - Close active window",
" wputc - Write character to active window",
" wclwin - Clear active window",
" wcleow - Clear to end of active window",
" wcleol - Clear to end of line in active window",
" w_close - Close any window",
" w_putc - Write character to any window",
" w_clwin - Clear any window",
" w_cleow - Clear to end of any window",
" w_cleol - Clear to end of line in any window",
"",
"Press any key to proceed...",
0 };
char *basic2[] = { /* Screen 2 */
"",
"More basic functions:",
"",
" wgotoxy - Position cursor in active window",
" wupdatexy - Update cursor position in current window",
" wgetc - Get character with cursor in active window",
" wtstc - Test for character with cursor in active window",
" w_gotoxy - Position cursor in any window",
" w_updatexy - Update cursor position in any window",
" w_getc - Get character with cursor in any window",
" w_tstc - Test for character with cursor in any window",
" wcursor_off - Turn cursor off *",
" wcursor_line - Turn cursor on as a line *",
" wcursor_block- Turn cursor on as a block *",
"",
"* The cursor is saved/restored when windows are opened/closed",
"",
"Press any key to proceed...",
0 };
/* Rambling about supplementary video functions */
char *supp1[] = {
"",
"The supplementary video functions (written in 'C' are):",
"",
" wputs - Write a string to active window",
" wputf - Write a string in a field to active window",
" wprintf - Perform 'printf' to active window",
" wgets - Get a string (with editing) in active window",
" wmenu - Perform a multiple selection menu in window",
" wform - Display/update an input form in window",
" w_puts - Write a string to any window",
" w_printf - Perform 'printf' to any window",
"",
"Press any key to proceed...",
0 };
/*
* Main function, present main menu & execute sub-functions
*/
main()
{
int m1;
m1 = 0;
titlewin = wopen(0, 0, 80, 3, WBOX2|WCOPEN|0x47);
color = (W_BASE == 0xB000) ? m_colors : c_colors;
wopen(0,3,80,22,WSAVE|WBOX1|WCOPEN|0x30);
wcursor_off();
title("MICRO-C Windowing Demonstration");
help(intro);
wgetc();
wclwin();
for(;;) {
title("MICRO-C Window Library Demonstration - ESC to exit");
if(wmenu(12, 5, WBOX1|WCOPEN|color[MENU], main_menu, &m1))
break;
switch(m1) {
case 0 : /* Library function info */
help(basic1);
wgetc();
help(basic2);
wgetc();
help(supp1);
wgetc();
break;
case 1 : /* Window creation demo */
create_demo();
break;
case 2 : /* Scrolling window demo */
scroll_demo();
break;
case 3 : /* Concurrent window demo */
simul_demo();
break;
case 4 : /* Form entry demo */
form_demo();
break;
case 5 : /* Window attribute demo */
attr_demo();
break;
case 6 : /* Set window colors */
set_colors();
break;
case 7 : /* Clear main window */
wclwin();
break; } }
title("Demonstration Complete");
wclose();
wclose();
}
/*
* Draw a title on the title window
*/
title(string)
char *string;
{
w_clwin(titlewin);
w_gotoxy((78/2) - (strlen(string)/2), 0, titlewin);
w_puts(string, titlewin);
}
/*
* Pause for a key to be pressed
*/
pause()
{
wopen(22, 12, 37, 5, WSAVE|WBOX2|WCOPEN|color[PAUSE]);
wcursor_off();
wgotoxy(5, 1);
wputs("Press any key to proceed...");
wgetc();
wclose();
}
/*
* Display help text on the screen
*/
help(text)
char *text[];
{
int i;
char *ptr;
wclwin();
i = 0;
while(ptr = text[i]) {
wgotoxy(0, i++);
wputs(ptr); }
}
/*
* Set the window colors
*/
set_colors()
{
int c, f, b;
char buffer[50];
c = 0;
wopen(15, 9, 50, 11, WSAVE|WBOX1|WCOPEN|color[TEXT]);
wcursor_off();
wputs("Use PgUp and PgDn to select window\n\n");
wputs("Up and Down arrows to select FOREGROUND color\n");
wputs("Left and Right arrows to select BACKGROUND color\n");
wputs("Press ESCAPE to exit this function");
for(;;) {
sprintf(buffer, "COLOR selection menu: %s", menu1[c]);
title(buffer);
b = color[c] >> 4;
f